package _99练习;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Baozi3 extends Thread{

	String name;
	int count=100;
	Lock l = new ReentrantLock();
	
	public void run() {
		
		while(count>0)
		{
			if(l.tryLock())
			{
				if(count>0)
				{
					count--;
					System.out.println(name+"正在吃第"+count+"个包子");
				}
				l.unlock();
			}
			else
			{
				System.out.println(name+"正在吃第"+count+"个包子");
			}
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	synchronized public void eato() {
		count--;
		System.out.println(Thread.currentThread().getName()+"吃了还剩下"+count+"个包子");
	}
}